// 221021 liang 获取权限列表封装，基于 pages/authority/permission.js getAuthorityList2 函数
const getAuthorityList = (fid, pid, rid) => {
  let post = {
    user_id: wx.getStorageSync('user_id'),
    function_id: fid,
    pare_id: pid || '',
    row_id: rid,
  }
  return new Promise((resolve, reject) => {
    wx.$post(4, 'QX/PRO_QX_list', post).then(res => {
      if(res.errcode !== 0) return
      res = res.data
      let list = res.row || [],
          fieldSee = [],
          fieldAppend = [],
          fieldEdit = [],
          tableSee, tableAppend, tableDelete, tableEdit, tableImport, tableExport, see_range, tableDistribution, tableShare

      list.forEach(item => {
        let { function_id, function_type, is_see, is_append, is_edit, is_delete, is_distribution, is_share, } = item // import, export 是关键字，不能做变量名，see_range上面已经命名了
        if(function_type === '字段') {
          if(is_see) fieldSee.push(function_id)
          if(is_append) fieldAppend.push(function_id)
          if(is_edit) fieldEdit.push(function_id)
        }
  
        if(function_id === fid) {
          tableSee = is_see
          tableAppend = is_append
          tableEdit = is_edit
          tableDelete = is_delete
          tableImport = item.import
          tableExport = item.export
          see_range = item.see_range
          tableDistribution = is_distribution
          tableShare = is_share
        }
      })
      let obj = {
        fieldSee,
        fieldAppend,
        fieldEdit,
        tableSee,
        tableAppend,
        tableDelete,
        tableEdit,
        tableImport,
        tableExport,
        see_range,
        tableDistribution,
        tableShare,
      }
      resolve(obj)
    })
  })
}

wx.$getAuth = getAuthorityList